package cn.hello1023.springbootlabs.controller;

import cn.hello1023.springbootlabs.pojo.CommonResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class MyExceptionHandle {

    @ExceptionHandler(value = {ArithmeticException.class})
    public CommonResult<?> myHandle1(Exception e){
        System.out.println("Catch an exception!");
        System.out.println(e);
        return CommonResult.error(999, String.format("系统异常:%s", e.getMessage()));
    }

    @ExceptionHandler(value = Exception.class)
    public void myHandle2(){
        System.out.println("Catch an exception!");
    }
}
